//
//  NSString+MD5.m
//  高仿暴走斗图
//
//  Created by huangsongyao on 16/3/7.
//  Copyright © 2016年 huangsongyao. All rights reserved.
//

#import "NSString+MD5.h"
#import <CommonCrypto/CommonDigest.h>

@implementation NSString (MD5)

- (NSString *)md5 {
    const char *str = [self UTF8String];
    unsigned char hash[16];
    CC_MD5(str, (CC_LONG)strlen(str), hash);
    NSMutableString *result = [NSMutableString string];
    for (int i = 0; i < 16; ++i) {
        [result appendFormat:@"%02X", hash[i]];
    }
    return result;
}

- (NSString *)md5Lower {
    const char *str = [self UTF8String];
    unsigned char hash[16];
    CC_MD5(str, (CC_LONG)strlen(str), hash);
    NSMutableString *result = [NSMutableString string];
    for (int i = 0; i < 16; ++i) {
        [result appendFormat:@"%02x", hash[i]];
    }
    return result;
}

- (NSString *)md5Upper {
    return [self md5];
}



@end
